<template>
	<view>
		<st-mc-framework navTitle="古越电源注塑MES" @changeLevel="changeLevel">
			<template #workbench>
				<view class="TabsBox">


				</view>


			</template>

			<!-- 主内容 -->
			<template #content>
				<view class="content_box f-dc">
					<view class="table table_top_th">
						<table>
							<tr>
								<th width='12%'>检验编号</th>
								<th width='20%'>产品名称</th>
								<th width='10%'>检验日期</th>
								<th width='10%'>检验数量</th>
								<th width='10%'>合格数量</th>
								<th width='10%'>不合格数量</th>
								<th width='8%'>不良率</th>
								<th width='10%'>检验结果</th>
								<th width='10%'>是否审核</th>
							</tr>

						</table>
					</view>
					<z-paging ref="paging" v-model="contents" @query="queryList" :fixed="false" class="z_paging">
						<view class="table">

							<table style="table-layout: fixed;">

								<tbody>
									<tr v-for="(item,index) in contents" @click="planIDClick(item,index)"
										:class="{ hovered: hoveredIndex === index }">
										<td width='12%'>{{item.BillNO}}</td>
										<td width='20%'>
											<view class="ListTdDiv"><text>{{item.ProductName}}</text></view>
										</td>
										<td width='10%'>{{item.BillDate}}</td>
										<td width='10%'>{{item.CkAmount}}</td>
										<td width='10%'>{{item.OkAmount}}</td>
										<td width='10%'>{{item.BadAmount}}</td>
										<td width='8%'>{{item.BadRate}}</td>
										<td width='10%'>{{item.Result}}</td>
										<td width='10%'>{{item.Approve?'已审核':'未审核'}}</td>
									</tr>
								</tbody>
							</table>

						</view>

					</z-paging>

				</view>

				<!-- <view class="add">
					<u-icon name="scan" color="#fff" size="30" @click="scan"></u-icon>
				</view> -->
				<view class="search">
					<u-icon name="search" color="#fff" size="30" @click="search"></u-icon>
				</view>

				<uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0"
					@change="changePopup">
					<view class="popup_content">

						<u-cell-group :border='false'>
							<u-cell title="开始时间" :isLink="false" :value='FormData.FBDate'
								@click="addTime('开始')"></u-cell>
							<u-cell title="结束时间" :isLink="false" :value='FormData.FEDate'
								@click="addTime('结束')"></u-cell>
							<u-cell title="是否审核" :isLink="false" :value="FormData.Approve?'已审核':'未审核'"
								@click="addIsStart()"></u-cell>
						</u-cell-group>
						<view class="bottomBtns">
							<button block @click="submit">
								查 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 询
							</button>
						</view>

					</view>
				</uni-popup>
				<u-datetime-picker :show="show" v-model="value1" mode="date" @cancel='show = false' @close="show=false"
					@confirm='pickerConfirm'></u-datetime-picker>

				<u-action-sheet :actions="IsStartList" :show="IsStartShow" @select="IsStartClick"
					@close="IsStartShow=false"></u-action-sheet>
			</template>

		</st-mc-framework>
	</view>
</template>

<script>
	import {
		getTimeStamp,
		getFormatDateTime,
		getBefore7DateTime,
		formatDateTime,
		navigateMixin,
		baseAddModuleData_select,
		getchangeLevel
	} from '@/st_mes_zs/common/base.js';
	
	export default {
		mixins: [navigateMixin, baseAddModuleData_select],
		data() {
			return {
				FormData: {
					FWorkshopID: '1011',
					PageIndex: 1,
					PageSize: 30,
					FState: '',
					FBDate: '',
					FEDate: '',
					FType: 'CPJ',
					Approve: 0,
					EquipmentID: null

				},
				contents: [],
				show: false,
				value1: Number(new Date()),
				TimeName: '',
				hoveredIndex: null,
				IsStartShow: false,
				IsStartList: [{
						name: '未审核',
						id: 0
					},
					{
						name: '已审核',
						id: 1
					}
				],
				disabled: false,
			};
		},
		onLoad() {
			var that = this
			that.FormData.FBDate = getBefore7DateTime()
			that.FormData.FEDate = getFormatDateTime(new Date())
			that.$store.state.GuyueModule.MesBasicInfo.Status.ClockStatusTitle = '其他'
			that.FormData.EquipmentID = that.$store.state.GuyueModule.MesBasicInfo.warehouse.EquipmentID
		},
		onShow() {

			this.clearHovered();

			this.getList
		},
		onBackPress(options) { // 监听页面返回
			if (options.from == 'navigateBack') { // 通过点击路由返回
				return false;
			} else if (options.from == 'backbutton') { // 通过外置返回
				return true;
			}
		},
		mounted() {

		},
		methods: {
			getList() {
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			IsStartClick(e) {
				this.IsStartShow = false
				this.FormData.Approve = e.id
			},
			addIsStart() {
				this.IsStartShow = true
			},

			planIDClick(item, index) {
				let that = this;
				this.hoveredIndex = index; // 设置当前hover的tr索引  
				var url
				let routes = getCurrentPages();
				let obj = {
					Name: '',
					APPFunID: '',
					length: routes.length + 1
				}

				url = `./finishedinspectionDetail?InspectionID=${item.InspectionID}`

				obj.Name = '完工入库检详情'
				obj.APPFunID = '完工入库检详情'
				this.GonavigateTo(obj, url)
			},
			GonavigateTo(obj, url) {
				let that = this;
				if (that.disabled == false) {
					that.disabled = true
					let newData = JSON.parse(JSON.stringify(this.$store.state.GuyueModule.ModuleData_select));
					newData.push(obj);
					this.$store.commit('GuyueModule/ChangeAndSetStateData', {
						Name1: 'ModuleData_select',
						data: newData
					})
					uni.navigateTo({
						url: url,
						animationType: 'slide-in-right', // 动画类型
						animationDuration: 300 // 动画时长
					});
					setTimeout(() => {
						that.disabled = false
					}, 4000)
				}

			},
			addTime(name) {
				this.TimeName = name
				if (this.TimeName == '开始') {
					this.value1 = Number(getTimeStamp(this.FormData.FBDate))
				} else {
					this.value1 = Number(getTimeStamp(this.FormData.FEDate))
				}
				this.show = true
			},
			search() {
				this.$refs.popup.open('bottom')
			},
			submit() {
				let that = this;
				this.$refs.popup.close('bottom')
				this.contents = []; // 假设这是异步获取数据的操作
				this.$refs.paging.reload();
			},
			pickerConfirm(e) {
				let that = this;
				var time = getFormatDateTime(e.value)
				if (this.TimeName == '开始') {
					this.FormData.FBDate = time
				} else {
					this.FormData.FEDate = time
				}
				this.show = false
			},
			changePopup() {

			},

			queryList(pageNo) {
				let that = this;
				that.FormData.PageIndex = pageNo
				try {
					that.Request.request('getInspectionList', this.FormData, (ret) => {
						if (ret.status == 200) {
							that.$refs.paging.complete(ret.data.ds);
							that.$forceUpdate()
						}
					})
				} catch (e) {
					console.log(e)
					this.$utils.hideLoading();
					this.$utils.msg('请求失败请重试')
				}

			},

			changeLevel(list, data, row) {
				getchangeLevel(data)
				
			},
			clearHovered() {
				this.hoveredIndex = null; // 清除hover的tr索引  
			},

		}
	}
</script>

<style lang="scss" >
	@import "../css/index.css";
</style>